package com.lizhiyu.flink.demo2_source.paramlleism;

import com.lizhiyu.flink.model.VideoOrder;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.functions.source.RichSourceFunction;

import java.util.Date;

public class VideoCustomSource extends RichSourceFunction<VideoOrder> {
    @Override
    public void run(SourceContext<VideoOrder> sourceContext) throws Exception {
        while (true){
            Thread.sleep(1000L);
            VideoOrder videoOrder = new VideoOrder();
            videoOrder.setTradeNo("1");
            videoOrder.setTitle("1212");
            videoOrder.setMoney(6);
            videoOrder.setUserId(1);
            videoOrder.setCreateTime(new Date());
            sourceContext.collect(videoOrder);
        }
    }
    @Override
    public void cancel() {
        System.out.println("执行关闭方法");
    }

    @Override
    public void open(Configuration parameters) throws Exception {
        System.out.println("执行初始化方法、并发度有几个就执行几次open方法...");
    }
}
